package com.ibilibili.crawl;
import java.lang.Thread;
import com.ibilibili.utils.Consts;

public class CrawlThreadMain {
    public static void main(String[] args ) {
        int tidTotal = Consts.TIDTOTAL; // 需要爬取的tid总数
        int pnTotal = Consts.PNTOTAL;   // 需要爬取的pn总数
        int threadNum = Consts.THREADNUM;   // 总的线程数
        // 通过参数传入修改tid, pn, thread数量
        if (args.length == 3) {
            tidTotal = Integer.parseInt(args[0]);
            pnTotal = Integer.parseInt(args[1]);
            threadNum = Integer.parseInt(args[2]);
        }

        System.out.println("tidTotal: " + tidTotal + ", pnTotal: " + pnTotal + ", threadNum: " + threadNum);

        int taskNum = tidTotal / threadNum;
        int surplus = tidTotal % threadNum;
        for(int i = 0; i < threadNum; i++){
            int beginTid = i * taskNum;
            int endTid = (i + 1) * taskNum;
            if ((i + 1) == threadNum) {
                endTid += surplus;
            }

            Thread t = new CrawlThread(beginTid, endTid, 0, pnTotal);
            t.start();
        }
    }
}
